<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    /**
     * CURL
     * Untuk mengirimkan request pada suatu URL dengan method POST
     * dengan parameters tertentu, content-type: JSON
     *
     */
    function post($url, $params) {
        try {
            $post = json_encode($params);

            $this->curl->create($url);
            $this->curl->options(
                array(
                    CURLOPT_BUFFERSIZE => 128,
                    CURLOPT_HTTPHEADER => array(
                        'Content-Type: application/json; charset=utf-8',
                        'Content-Length: '.strlen($post)
                    )
                )
            );
            $this->curl->post($post);
            $result = $this->curl->execute();

            return $result;
        } catch (Exception $e) {
            return null;
        }
    }
}